<template>
	<view class="page">
		<view class="body" v-if="page_type == 1||page_type==3">
			<uni-section title="服务商昵称" type="line">
				<input type="text" placeholder="请输入服务商昵称" class="input_css" v-model="name" />
			</uni-section>
			<uni-section title="服务商手机号" type="line">
				<input type="text" placeholder="请输入服务商手机号" class="input_css" v-model="phone" />
			</uni-section>
			<uni-section title="登录密码" type="line">
				<input type="password" placeholder="请输入密码" class="input_css" v-model="password" />
			</uni-section>
			<uni-section title="确认登录密码" type="line">
				<input type="password" placeholder="请输入密码" class="input_css" v-model="password2" />
			</uni-section>
			<uni-section title="支付密码" type="line">
				<input type="password" placeholder="请输入支付密码" class="input_css" v-model="pay_password" />
			</uni-section>
			<uni-section title="确认支付密码" type="line">
				<input type="password" placeholder="请输入支付密码" class="input_css" v-model="pay_password2" />
			</uni-section>
			<uni-section title="费率" type="line">
				<input type="text" placeholder="请输入费率" class="input_css" v-model="rates" />
			</uni-section>
			<uni-section title="邀请人" type="line">
				<input type="text" placeholder="请输入邀请人" class="input_css" v-model="invite" />
			</uni-section>
			<uni-section title="服务商类型" type="line">
				<input type="text" placeholder="请输入邀请人" class="input_css" v-model="type" />
			</uni-section>
		</view>
		<view class="body" v-if="page_type == 2">
			<uni-section title="商家昵称" type="line">
				<input type="text" placeholder="请输入商家昵称" class="input_css" v-model="name" />
			</uni-section>
			<uni-section title="商家手机号" type="line">
				<input type="text" placeholder="请输入商家手机号" class="input_css" v-model="phone" />
			</uni-section>
			<uni-section title="登录密码" type="line">
				<input type="password" placeholder="请输入密码" class="input_css" v-model="password" />
			</uni-section>
			<uni-section title="确认登录密码" type="line">
				<input type="password" placeholder="请输入密码" class="input_css" v-model="password2" />
			</uni-section>
			<uni-section title="支付密码" type="line">
				<input type="password" placeholder="请输入支付密码" class="input_css" v-model="pay_password" />
			</uni-section>
			<uni-section title="确认支付密码" type="line">
				<input type="password" placeholder="请输入支付密码" class="input_css" v-model="pay_password2" />
			</uni-section>
			<uni-section title="费率" type="line">
				<input type="text" placeholder="请输入费率" class="input_css" v-model="rates" />
			</uni-section>
			<uni-section title="邀请人" type="line">
				<input type="text" placeholder="请输入邀请人" class="input_css" v-model="invite" />
			</uni-section>
			<uni-section title="商家类型" type="line">
				<input type="text" placeholder="请输入邀请人" class="input_css" v-model="type" />
			</uni-section>
		</view>
		<view class="btn_css">
			<view class="btn" @click="btn">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getOneSerivce,
		editSerivce,
		addSviceShop
	} from '../../api/busList/index.js'
	export default {
		data() {
			return {
				id: '',
				name: '',
				phone: '',
				password: '',
				password2: '',
				rates: '',
				pay_password: '',
				pay_password2: '',
				invite: '',
				type: '',
				page_type: '',
				shop_id: ''
			}
		},
		onLoad(e) {
			this.id = e.id;
			this.page_type = e.type;
			if (e.type == 1) {
				uni.setNavigationBarTitle({
					title: '编辑服务商'
				})
				this.init();
			} else if (e.type == 3) {
				uni.setNavigationBarTitle({
					title: '新增服务商'
				})
			} else if (e.type == 2) {
				uni.setNavigationBarTitle({
					title: '编辑商家'
				})
			}
		},
		methods: {
			init() {
				var data = {
					phone: this.id
				};
				getOneSerivce(data).then(res => {
					this.name = res.data.username;
					this.phone = res.data.mobile;
					this.password = res.data.password;
					this.password2 = res.data.password;
					this.rates = res.data.rate;
					this.pay_password = res.data.paypwd;
					this.pay_password2 = res.data.paypwd;
					this.invite = res.data.invite;
					this.type = res.data.providers_notice;
					this.shop_id = res.data.shop_id;
				})
			},
			btn() {
				const data = {
					shop_id: this.shop_id,
					rate: this.rates,
					mobile: this.phone,
					shop_name: this.name,
					paypwd: this.pay_password,
					paypwd_sec: this.pay_password2,
					password: this.password,
					password_sec: this.password2,
					providers_notice: this.type,
					invite: this.invite,
				}
				if (this.page_type == 1 || this.page_type == 2) {
					editSerivce(data).then(res => {
						console.log(res);
						uni.showToast({
							"icon": "none",
							"title": res.msg
						})
						setTimeout(function() {
							uni.navigateBack(-1)
						}, 1000);
					})
				} else if (this.page_type == 3) {
					var datas = {
						rate: this.rates,
						mobile: this.phone,
						shop_name: this.name,
						password: this.password,
						user_role: '服务商'
					}
					addSviceShop(datas).then(res => {
						uni.showToast({
							"icon": "none",
							"title": res.msg
						})
						setTimeout(function() {
							uni.navigateBack(-1)
						}, 1000);
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100%;

		.body {
			.input_css {
				background-color: #f5f6f9;
				padding: 30rpx;
				border-radius: 15rpx;
			}
		}

		.btn_css {
			padding-top: 50px;
		}
	}
</style>